/*
 * @Author: ZhangXingliang
 * @Date: 2021-11-19 15:26:50
 * @Last Modified by: ZhangXingliang
 * @Last Modified time: 2021-11-19 15:29:41
 */

/**
 *
 * fade
 * @export
 * @param {ImageData} imageData
 * @return {*}  {ImageData}
 */
export default function fade(
  imageData1: ImageData,
  imageData2: ImageData,
  weight1: number,
  weight2: number
): ImageData {
  let newImageData = new ImageData(imageData1.width, imageData1.height)
  for (let i = 0; i < imageData1.data.length / 4; i++) {
    let realIndex = i * 4
    newImageData.data[realIndex] =
      imageData1.data[realIndex] * weight1 +
      imageData2.data[realIndex] * weight2
    newImageData.data[realIndex + 1] =
      imageData1.data[realIndex + 1] * weight1 +
      imageData2.data[realIndex + 1] * weight2
    newImageData.data[realIndex + 2] =
      imageData1.data[realIndex + 2] * weight1 +
      imageData2.data[realIndex + 2] * weight2
    newImageData.data[realIndex + 3] =
      imageData1.data[realIndex + 3] * weight1 +
      imageData2.data[realIndex + 3] * weight2
  }
  return newImageData
}
